package com.oa.hyperion.api.v1;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.oa.hyperion.entity.Perm;
import com.oa.hyperion.service.PermService;
import com.oa.hyperion.service.RolePermService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Liu
 * @date 2022年01月18日 16:14
 */
@RestController
@RequestMapping("v1/perms")
@Api(tags = "rbac相关接口")
public class PermController {
    private final PermService permService;
    private final RolePermService rolePermService;
    public PermController(PermService permService, RolePermService rolePermService) {
        this.permService = permService;
        this.rolePermService = rolePermService;
    }

    @GetMapping
    @ApiOperation("获取所有的权限")
    public List<Perm> getAllPerms() {
        return permService.list();
    }

    @GetMapping("by/role/{id}")
    @ApiOperation("获取角色的权限")
    public List<Perm> getRolePerm(@PathVariable Integer id) {
        return rolePermService.findPermByRole(id);
    }

    @DeleteMapping("{id}")
    @ApiOperation("逻辑栓除权限")
    public String deletePerm(@PathVariable Integer id) {
        permService.update(new UpdateWrapper<Perm>().set("status", "n").eq("id", id));
        return "删除成功";
    }
}
